package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.UserFavoriteDTO;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserFavoriteCommand;
import com.cskaoyan.wordmemorize.service.UserPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/priviledge/favorite")
public class UserPriviledgeFavoriteController {

    @Autowired
    UserPrivilegeService userPrivilegeService;

    @PostMapping("cancel")
    public Result cancelFavoriteWord(@RequestBody List<Long> vocIds){
        long userID = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.cancelFavorite(vocIds, userID);
        return Result.ok();
    }

    @PostMapping("bulk")
    public Result batchAddFavoriteWord(@RequestBody List<UserFavoriteCommand> userFavoriteCommands){
        long userID = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.addFavoriteBulk(userFavoriteCommands, userID);
        return Result.ok();
    }

    @PostMapping("")
    public Result addFavoriteWord(@RequestBody UserFavoriteCommand userFavoriteCommand){
        long userID = StpKit.USER.getLoginIdAsLong();
        userPrivilegeService.addFavorite(userFavoriteCommand, userID);
        return Result.ok();
    }

    @GetMapping("list")
    public Result<PageDTO<UserFavoriteDTO>> getFavoriteWordList(PageRequest pageRequest){
        long userID = StpKit.USER.getLoginIdAsLong();
        PageDTO<UserFavoriteDTO> userFavoriteList = userPrivilegeService.getUserFavoriteList(pageRequest, userID);
        return Result.ok(userFavoriteList);
    }
}
